package pulsar

import (
	"github.com/apache/pulsar-client-go/pulsar"
	"github.com/apache/pulsar-client-go/pulsar/log"
	"time"
)

type PubOptions struct {
	URL                     string                    `mapstructure:"url" json:"url" toml:"url"`
	Topic                   string                    `mapstructure:"topic" json:"topic" toml:"topic"`
	Name                    string                    `mapstructure:"name" json:"name" toml:"name"`
	SendTimeout             time.Duration             `mapstructure:"send_timeout" json:"send_timeout" toml:"send_timeout"`
	MaxPendingMessages      int                       `mapstructure:"max_pending_messages" json:"max_pending_messages" toml:"max_pending_messages"`
	BatchingMaxMessages     uint                      `mapstructure:"batching_max_messages"`      // default 1000
	BatchingMaxPublishDelay int                       `mapstructure:"batching_max_publish_delay"` // unit is ms default 10
	BlockIfQueueFull        bool                      `mapstructure:"block_if_queue_full" json:"block_if_queue_full" toml:"block_if_queue_full"`
	DisableBatching         bool                      `mapstructure:"disable_batching" json:"disable_batching" toml:"disable_batching"`
	CompressionType         int                       `mapstructure:"compression_type" json:"compression_type" toml:"compression_type"`
	Retry                   int                       `mapstructure:"retry" json:"retry" toml:"retry"`
	BatcherBuilderType      pulsar.BatcherBuilderType `mapstructure:"batcher_builder_type" json:"batcher_builder_type" toml:"batcher_builder_type"`
	MaxReconnectToBroker    uint                      `mapstructure:"max_reconnect_to_broker" json:"max_reconnect_to_broker" toml:"max_reconnect_to_broker"`
	DisableAutoInit         bool                      `mapstructure:"disable_auto_init" json:"disable_auto_init" toml:"disable_auto_init"`
	Logger                  log.Logger
}

type SubscriptionType = pulsar.SubscriptionType

type SubOptions struct {
	URL                  string           `mapstructure:"url" json:"url" toml:"url"`
	Topic                string           `mapstructure:"topic" json:"topic" toml:"topic"`
	Topics               []string         `mapstructure:"topics" json:"topics" toml:"topics"`
	SubscriptionName     string           `mapstructure:"subscription_name" json:"subscription_name" toml:"subscription_name"`
	SubscriptionType     SubscriptionType `mapstructure:"subscription_type" json:"subscription_type" toml:"subscription_type"`
	NotPtMessage         bool             `mapstructure:"not_pt_message" json:"not_pt_message" toml:"not_pt_message"`
	AckType              int              `mapstructure:"ack_type" json:"ack_type" toml:"ack_type"`
	MaxReconnectToBroker uint             `mapstructure:"max_reconnect_to_broker" json:"max_reconnect_to_broker" toml:"max_reconnect_to_broker"`
	DisableAutoInit      bool             `mapstructure:"disable_auto_init" json:"disable_auto_init" toml:"disable_auto_init"`
	ReceiverQueueSize    int              `mapstructure:"receiver_queue_size" json:"receiver_queue_size" toml:"receiver_queue_size"`
	Logger               log.Logger
}

type Config struct {
	Subscribers map[string]SubOptions `mapstructure:"subscribers"`
	Publishers  map[string]PubOptions `mapstructure:"publishers"`
}
